import { BlockEnum, CommonNodeType, NodeDefault } from '@/components/workflow/types'
import { generateUUID } from '@/utils'
import { ALL_COMPLETION_AVAILABLE_BLOCKS } from '../../constants'
import { InputVar, OutputVar } from '../types'

export type KnowledgeListType = {
  id: number
  name: string
  icon?: string
  description?: string
}

export type KnowledgeNodeType = CommonNodeType & {
  inputList: InputVar[]
  knowledgeList: KnowledgeListType[]
  outputList: OutputVar[]
}
export const getCodeDefaultParams = (): any => {
  return {
    inputList: [getCodeInputListParams("arg1"), getCodeInputListParams("arg2")],
    code: `# def main(arg1: str, arg2: str) -> dict 这行代码定义了函数 main。\n# (arg1: str, arg2: str): 这个函数的参数列表，指定了两个参数：arg1和 arg2。\n# 注意\n#   1.输入类型需要与右侧面板 \"输入\" 的变量名称与变量类型一一对应\n# arg1 += \"222\"  这行代码将字符串 \"222\"附加到 arg1 的末尾\n# 输出字典键是 \"output\"，值是 arg1和 arg2的连接结果。\n# 注意：\n#   2.返回的对象类型需要与右侧面板 \"输出\" 的变量名称与变量类型一一对应\n\ndef main(arg1: str, arg2: str) -> dict:\n  arg1 += \"222\"\n  return {\n    \"output\": arg1 + arg2,\n  }`,
    // 输出
    outputList: [
      {
        variable: 'output',
        value: '',
        type: 'str',
        value_selector: []
      }
    ]
  }
}

export const getCodeInputListParams = (variable: string): InputVar => {
  return {
    id: generateUUID(8),
    type: 'cite',
    label: '',
    variable,
    value: '',
    max_length: 10,
    default: '',
    required: true,
    options: [],
    value_selector: []
  }
}

const nodeDefault: NodeDefault<KnowledgeNodeType> = {
  defaultValue: { ...getCodeDefaultParams() },
  getAvailablePrevNodes() {
    const nodes = ALL_COMPLETION_AVAILABLE_BLOCKS.filter(type => type !== BlockEnum.End)
    return nodes
  },
  getAvailableNextNodes() {
    const nodes = ALL_COMPLETION_AVAILABLE_BLOCKS
    return nodes
  },
  checkValid(payload: KnowledgeNodeType) {
    let isValid = true
    let errorMessages = ''
    if (payload.type) {
      isValid = true
      errorMessages = ''
    }
    return {
      isValid,
      errorMessage: errorMessages
    }
  }
}

export default nodeDefault
